var mysql = require('mysql')

module.exports = {
    login: (obj, callback) => {
        var sql = 'select * from users where name=? and password=?'
        var parms = [obj.name, obj.pass]
        console.log('db=========query parms')
        console.log(parms)
        var con = mysql.createConnection({
            host: 'localhost',
            port: 3306,
            database: 'test',
            user: 'test',
            password: 'test'
        })
        con.connect()

        con.query(sql, parms, (err, result) => {
            if (err) {
                return callback(err, null)
            }
            if (result.length > 0) {
                callback(null, 'success')
            } else {
                callback('no this user', null)
            }
        })
        con.end()
    }
}